/**
 * 
 */
package com.googlecode.agiletools.backlog;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Administrator
 * 
 */
public class SprintBacklogManager {

    private HibernateTemplate hibernateTemplate;

    /**
     * @param backlogId
     * @return
     */
    public SprintBacklog getBacklog(int id) {
	return (SprintBacklog) hibernateTemplate.get(SprintBacklog.class, id);
    }

    /**
     * @param backlog
     * @return
     */
    @Transactional(readOnly = false)
    public SprintBacklog saveBacklog(SprintBacklog backlog) {
	for (SprintTask task : backlog.getTasks()) {
	    task.setBacklog(backlog);
	    task.setSeq(backlog.getTasks().indexOf(task));
	}
	hibernateTemplate.saveOrUpdate(backlog);
	backlog.resetLeftEfforts();
	return backlog;
    }

    /**
     * @param hibernateTemplate
     *            the hibernateTemplate to set
     */
    public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
	this.hibernateTemplate = hibernateTemplate;
    }

}
